home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
cpp_libs
/
rjs.lha
/
RJS
/
Transport
/
src
/
Transport.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-14
|
2KB
|
97 lines
#include <libc.h>
#include <osfcn.h>
#include <sys/uio.h>
#include <iostream.h>
#include <errno.h>
#include "Transport.h"
#include <RJS/Util.h>
RJS_Transport::RJS_Transport()
{
td = -1;
ss_set(SS_success);
return_on_error=0;
}
int RJS_Transport::close()
{
if (td == -1) { ss_set(SS_success); return 1; }
int s = ::close(td);
if (s==-1) {
ss_set(RJS_Status(errno));
if (return_on_error) return 0;
RJS_Util::crash_and_burn("RJS_Transport","close",ss_message());
}
else {
ss_set(SS_success);
td=-1;
return 1;
}
}
int RJS_Transport::ok()
{
if (td==-1) return 0;
else return RJS_Status::ss_ok();
}
int RJS_Transport::inuse()
{
return (td!=-1);
}
int RJS_Transport::read(char *buffer, int mlen)
{
if (td == -1) return -1;
int nbr = ::read(td,buffer,mlen);
if (nbr==-1) {
ss_set(RJS_Status(errno));
if (return_on_error) return nbr;
RJS_Util::crash_and_burn("RJS_Transport","read",ss_message());
}
else ss_set(SS_success);
return nbr;
}
int RJS_Transport::readv(const struct iovec *iov, int iovlen)
{
if (td == -1) return -1;
int nbr = ::readv(td,iov,iovlen);
if (nbr==-1) {
ss_set(RJS_Status(errno));
if (return_on_error) return nbr;
RJS_Util::crash_and_burn("RJS_Transport","readv",ss_message());
}
else ss_set(SS_success);
return nbr;
}
int RJS_Transport::write(const char *buffer, int len)
{
if (td == -1) return -1;
int nbw = ::write(td,buffer,len);
if (nbw==-1) {
ss_set(RJS_Status(errno));
if (return_on_error) return nbw;
RJS_Util::crash_and_burn("RJS_Transport","write",ss_message());
}
else ss_set(SS_success);
return nbw;
}
int RJS_Transport::writev(const struct iovec *iov, int iovlen)
{
if (td == -1) return -1;
int nbw = ::writev(td,iov,iovlen);
if (nbw==-1) {
ss_set(RJS_Status(errno));
if (return_on_error) return nbw;
RJS_Util::crash_and_burn("RJS_Transport","writev",ss_message());
}
else ss_set(SS_success);
return nbw;
}